package com.houxm.logic.impl;

import java.security.NoSuchAlgorithmException;

import com.houxm.dao.UserDao;
import com.houxm.entity.User;
import com.houxm.logic.LoginLogic;
import com.houxm.util.MD5;

public class LoginLogicImpl implements LoginLogic {

	private UserDao userDao = null;
	
	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public User login(String username, String password) {
		User user = null;
		user = this.getUserInfo(username);
		try {
			if(user!=null && MD5.encryption(password).equals(user.getPassword()))
			{
				return user;
			}
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return null;
	}

	public User getUserInfo(String username) {
		return userDao.getUserByUsername(username);
	}

}
